# class Person:
#     def __init__(self, name,age,weight):
#         self.name = name
#         self.age = age
#         self.weight = weight
#
#     def run(self):
#         self.weight-=0.5
#         print(f'{self.name}跑步了，体重减少了0.5公斤{self.weight}')
#
#     def eat(self):
#         self.weight+=1
#         print(f'{self.name}吃大餐，体重增加1公斤{self.weight}')
#     def __str__(self):
#         return f'{self.name}体重现在是{self.weight}'

# elephant=Person ('大象',18,80)
# elephant.run()
# elephant.eat()
# print(elephant)

class HouseItem:
    def __init__(self,name,area):
        self.name=name
        self.area=area
    def __str__(self):
        return "[%S]占地 %.2f"%(self.name,self.area)

class House:
    def __init__(self,house_type,area): #冒号：类名是注解的作用，协助写代码
        self.house_type=house_type
        self.area=area
        self.free_srea=area #剩余面积
        self.item_list=[] #创建家具
    def add(self,item:HouseItem):
        print(f'要添加{item}')
        if self.free_srea >= item.area:
            self.item_list.append(item.name)
            self.free_srea-=item.area
        else:
            print('房间空间不足')

    def __str__(self):
        return ("户型:%s \n总面积：%。2f[剩余：%。2f]\n家具:%s"
                %(self.house_type,self.area,self.free_srea,self.item_list))

# 1，创建家具
bad=HouseItem("席梦思",4)
chest=HouseItem("衣柜",2)
table=HouseItem("餐桌",1.5)

# print(bad)
# print(chest)
# print(table)
house=House('三室一厅',70)
print(house)
house.add_item(bad)
print(house)